
var aspectRatioFactor = {
    x: 854,
    y: 480,
    d: 3.67
};

var TR_USERLAYER_CELL_WIDTH =  (123/(2*4));
var TR_USERLAYER_CELL_HEIGHT = (63/(2*4)); //32
var CELL_WIDTH_OFFSET = 1.5;
var CELL_HEIGHT_OFFSET = 6;
var TR_DIAMOND_LAYER_MARGIN_WIDTH  = 150;
var TR_DIAMOND_LAYER_MARGIN_HEIGHT = 300;

var DIAMOND_WIDTH = 0;
var DIAMOND_HEIGHT = 0;

exports.TCUtil = Core.Class.singleton(
{
								 
	blockingView:null,
	imageView:null,
	classname:'TCUtil',
	initialize: function() 
    {
		this._zIndexArray = null;
		this._arrayFilled = false;							  
							  
	},
	
	getAdjustedFontSize: function(fieldHeight) {
        return this.getAdjustedY(fieldHeight / 2) / aspectRatioFactor.d;
    },
    
    getItemType: function(item)
    {
		if(item) 
		{
			{
				var storeVisibleId = item.parent.parent.visible_id;			 
									
				if(storeVisibleId) 
				{
					if(storeVisibleId == '1') 
					{
						return kItemType.kItemStore;
					}
					
					else if(storeVisibleId == '2') 
					{
						return kItemType.kItemDecoration;
					}
					
					else if(storeVisibleId == '3')
					{
						return kItemType.kItemTemporary;
					}	
					
					else if(storeVisibleId == '4')
					{
						return kItemType.kItemLift;
					}	
				}
			}
		}		
    },
	
	
	setWidth: function(width)
	{
		DIAMOND_WIDTH = width;
	},
	
	setHeight: function(height)
	{
		DIAMOND_HEIGHT = height;
	},
	
	adjustWidthHeightWithDevice: function(aWidth, aHeight)
	{
		var w = 0 , h = 0 , calWidth = 0 , calHeight = 0;
		w = Core.Capabilities.getScreenWidth();
		h = Core.Capabilities.getScreenHeight();
		
		calWidth = aWidth * (w/this.getBaseWidth());
		calHeight = aHeight * (h/this.getBaseHeight());
		
		//a memory leak if this is not released, have to fix it... //harris.
		return new Core.Vector(calWidth,calHeight);		
	},
	
	adjustWidthWithDevice: function(aWidth)
	{
		var w = 0, calWidth = 0;
		
		w = Core.Capabilities.getScreenWidth();
		
		calWidth = aWidth * (w/this.getBaseWidth());
		//////NgLogE('Bandri Width:'+aWidth +'-->'+calWidth +'device W:'+w);
		return calWidth;			
	},
	adjustHeightWithDevice: function(aHeight)
	{
		var h = 0 , calHeight = 0;
		
		h = Core.Capabilities.getScreenHeight();
		
		calHeight = aHeight * (h/this.getBaseHeight());
		//////NgLogE('Bandri Width:'+aHeight +'-->'+calHeight +'device H:'+h);
		return calHeight;		
		
	},
	
	getBaseWidth: function() {
		return 320;
	},

	getBaseHeight: function() {
		return 480;
	},
	
	getScreenWidth: function() {
		var width = Core.Capabilities.getScreenWidth();
		return width;
	},

	getScreenHeight: function() {
		var height = Core.Capabilities.getScreenHeight();
		return height;
	},
	
	getAdjustedWidth: function(w) {
		
		var width = Core.Capabilities.getScreenWidth();
		
       return (w / aspectRatioFactor.x) * width;
   },
 	
 	getAdjustedHeight: function(h) {
 		var height = Core.Capabilities.getScreenHeight();
       return (h / aspectRatioFactor.y) * height;
   },
     
   getAdjustedX: function(x) {
   		
   		var width = 0 , newWidth = 0 ;
   		width = Core.Capabilities.getScreenWidth();
   		newWidth = (width / this.getBaseWidth()) * x;
   		
       	return newWidth;
   		
   },
    
   getAdjustedY: function(y) 
   {
   		var height = 0 , newHeight = 0;
		height = Core.Capabilities.getScreenHeight();
		newHeight = (height / this.getBaseHeight()) * y;
      
       return newHeight;
   },
   
   	isAndroid: function() {
        return ( Core.Capabilities.getPlatformOS() == 'Android');
    },
    
	convertGridPointToWithInLayerPoint: function(point,gridSizeSent)
    {

        
        point.setX(point.getX()*(TR_USERLAYER_CELL_WIDTH + CELL_WIDTH_OFFSET));
        point.setY(point.getY()*(TR_USERLAYER_CELL_HEIGHT + CELL_HEIGHT_OFFSET));
        
        var xShear = 0 , x = 0 , y = 0 , width = 0 , height = 0 , gridSize = 0;
        
        xShear = -0.73;
        point.setX(point.getX()+(point.getY()*xShear));
        //////NgLogE("value is >> "+point.getX());
        
        x = point.getX() * 0.894427191000276 - point.getY() * 0.447213595499237;
        y = point.getX() * 0.447213595499237 + point.getY() * 0.894427191000276;	
        ////NgLogE("converting the values "+TR_USERLAYER_CELL_WIDTH+" plus "+point.getX() );
        
        gridSize = gridSizeSent.getX();
        x = x + gridSize * TR_USERLAYER_CELL_WIDTH;
        
        width = (gridSizeSent.getX()/4) * TR_USERLAYER_CELL_WIDTH;
        height = (gridSizeSent.getY()/4) * TR_USERLAYER_CELL_HEIGHT;
        
        
        x = x - (4*width);
        y = height - y - (height);

        
        
        return (new Core.Vector(x,y));
    },
    
	convertGridPointToLayerPoint: function(posVector)
    {
		////NgLogE("grid: x , y " + posVector.getX() + " " + posVector.getY());
		var newVector = 0 , xShear = 0 , x = 0 , y = 0 , gridSize = 0;

        ////NgLogE("tcUtil being called " +DIAMOND_HEIGHT);
		////NgLogE("____ initial vector is X "+posVector.getX()+" and y was "+posVector.getY());
        newVector = new Core.Vector();
        newVector.setX(posVector.getX() *(TR_USERLAYER_CELL_WIDTH + CELL_WIDTH_OFFSET));
        newVector.setY(posVector.getY() *(TR_USERLAYER_CELL_HEIGHT + CELL_HEIGHT_OFFSET));
        
        ////NgLogE("___1converstion result is X "+newVector.getX()+" and y is "+newVector.getY());
        
        xShear = -0.73;
        newVector.setX(newVector.getX() + (newVector.getY()*xShear));
        ////NgLogE("___2converstion result is X "+newVector.getX()+" and y is "+newVector.getY());
        
        
      	x = newVector.getX() * 0.894427191000276 - newVector.getY() * 0.447213595499237;
        y = newVector.getX() * 0.447213595499237 + newVector.getY() * 0.894427191000276;	
        //NgLogE("___3converstion result is X "+x+" and y is "+y);
        
        gridSize = MMGameState.getCurrentUser().getSelectedZoo().getGridRows();
        
        x = x + gridSize*TR_USERLAYER_CELL_WIDTH;
        //NgLogE("___4converstion result is X "+x+" and y is "+y);
        
        x = x + TR_DIAMOND_LAYER_MARGIN_WIDTH;
        y = y + TR_DIAMOND_LAYER_MARGIN_HEIGHT;
        
        //NgLogE("___5converstion result is X "+x+" and y is "+y);
        x = x - DIAMOND_WIDTH/2;
        y = DIAMOND_HEIGHT - y - (DIAMOND_HEIGHT/2);
        //y = -300;
        //y = this._height - y;
        
        newVector = new Core.Vector(x,y);
        // NgLogE("layer: x , y " + newVector.getX() + " " + newVector.getY());
        //NgLogE("___final result is X "+newVector.getX()+" and y is "+newVector.getY());
        return newVector;
		
    },
	
	convertLayerPointToGridPoint: function(point)
    {
    	//var sprite = MMGameLayer.getMyUserLayer()._motherSprite;
    	//var againPoint = sprite.screenToLocal(point);
        //NgLogE("initializeVIsitorUIlayer: x , y " + point.getX() + " " + point.getY());
        var gridSize = 0 , x = 0 , y = 0 , xShear = 0 , resultVector = 0;
        
        gridSize = MMGameState.getCurrentUser().getSelectedZoo().getGridRows();
        //NgLogE("initializeVIsitorUI GridSize: x , y " + gridSize);
        
		point.setX(point.getX()+DIAMOND_WIDTH/2);
        point.setY(-point.getY()+DIAMOND_HEIGHT/2);

		
        point.setX(point.getX() - gridSize*TR_USERLAYER_CELL_WIDTH)
        
        point.setX(point.getX() - TR_DIAMOND_LAYER_MARGIN_WIDTH);
        point.setY(point.getY() - TR_DIAMOND_LAYER_MARGIN_HEIGHT);
        
        x = point.getX() * 0.894427191000276 - point.getY() * (-0.447213595499237);
        y = point.getX() * (-0.447213595499237) + point.getY() * 0.894427191000276;	
        
        xShear = 0.73;
        x = x + y*xShear;
        
        x = x / (TR_USERLAYER_CELL_WIDTH + CELL_WIDTH_OFFSET);
        y = y / (TR_USERLAYER_CELL_HEIGHT + CELL_HEIGHT_OFFSET);
        
        resultVector = new Core.Vector(Math.ceil(x),Math.ceil(y));
      //  //NgLogE("grid: x , y " + resultVector.getX() + " " + resultVector.getY());
        return resultVector;
        
        /*
        int gridSize = [[[GameState sharedGameState].currentUser getSelectedZoo] gridCols];
        
        ////Transforme axis to middle
        point.x = point.x - gridSize*TR_USERLAYER_CELL_WIDTH; 
        
        ///Diamond layer margin
        point.x = point.x - TR_DIAMOND_LAYER_MARGIN_WIDTH;
        point.y = point.y - TR_DIAMOND_LAYER_MARGIN_HEIGHT;
        
        
        ///Rotation Transform at angle 26
        ///	cos(-0.463647609) = 0.894427191000276
        /// sin(-0.463647609) = -0.447213595499237
        float x = point.x * 0.894427191000276 - point.y * (-0.447213595499237);
        float y = point.x * (-0.447213595499237) + point.y * 0.894427191000276;	
        
        ///Sheare Transform added
        float xShear = 0.73;
        x = x + y*xShear;
        
        //offset 
        x = x / (TR_USERLAYER_CELL_WIDTH + CELL_WIDTH_OFFSET);
        y = y / (TR_USERLAYER_CELL_HEIGHT + CELL_HEIGHT_OFFSET);
        
        return CGPointMake(floor(x),floor(y));
        */
    },

	
    getRelativeString: function(stringValue ,replaceValueArray)
    {
		var i;
	    for(i=0;i<replaceValueArray.length ;i++)
		{
		    stringValue = stringValue.replace("%val"+(i+1) ,replaceValueArray[i]);
		}

    	return stringValue;

    },
    
	
    zIndexAtGridPoint: function(gridPoint){
		////NgLogE('the value recieved for grid point x+'+gridPoint.getX()+'and y='+gridPoint.getY());
		if(!this._arrayFilled) {
			TCUtil.initializezIndexArray();
	     }
		//gridsize will be made generic later 
		var gridSize = MMGameState.getCurrentUser().getSelectedZoo().getGridRows();
		if(gridPoint.getX() < 0 || gridPoint.getY() < 0 || gridPoint.getX() >= gridSize || gridPoint.getY() >= gridSize ){
			return (gridSize*2 + 1) - (gridPoint.getX() + gridPoint.getY() +1);
		}
		else{
		
			return this._zIndexArray[gridPoint.getX()][gridPoint.getY()];
		}
	},
	
	initializezIndexArray: function()
	{
	if(this._arrayFilled) return;
	if(this._zIndexArray)
	{
		var count = this._zIndexArray.length, i=0;
		for(; i < count ; i++)
		{
									  
			delete this._zIndexArray[i];
			
		}
		delete this._zIndexArray;
	}
	this._zIndexArray = new Array(MMGameState.getCurrentUser().getSelectedZoo().getGridRows());								  
	var gridRows = MMGameState.getCurrentUser().getSelectedZoo().getGridRows();//[[GameState sharedGameState].currentUser getSelectedZoo].gridRows;
	var currentZIndex = 1;
	var i,j,x,y;
	
	for(x = 0 ; x < gridRows ; x++)
	{
		this._zIndexArray[x] = new Array(gridRows);	
	}
/*	
//	//old code to decide the zIndex
	
	for( x = 0; x < gridRows ; x++) {
		i = 0;
		j = x;
		for(y = 0; y < x+1 ; y++) {
			this._zIndexArray[gridRows - 1 - i][gridRows - 1 - j] = currentZIndex++;
			i+=1;
			j-=1;
		}
	}
	
	var value = 1;
	for(x = gridRows-1; x > 0 ; x--) {
		i = value;
		j = gridRows-1;
		for(y = 0; y < x ; y++) 
		{
		this._zIndexArray[ gridRows - 1 - i][gridRows - 1 - j] = currentZIndex++;
		i+=1;
		j-=1;
		}
		value ++;
	}
	
	//end  of old code
	
	*/
	
	
	
	
//added by washaq
	var startIndex = 1;								 
	for(x = gridRows-1 ;x >= 0 ; x--)
	{
		currentZIndex = startIndex;							 
		this._zIndexArray[x][x] = currentZIndex;
		for(y=x-1 ;y>=0 ;y--)
		{
			currentZIndex++;						 
			this._zIndexArray[x][y] = currentZIndex;
			this._zIndexArray[y][x] = currentZIndex;
		}
	startIndex+=2;					
	}
	 
	
   this._arrayFilled = true;
	},
    

	zIndexAtGridPointForWithinHabitat:function (gridPoint,gridSize)
	{
		TCUtil.initializezIndexArray();
		if(gridPoint.getX() < 0 || gridPoint.getY() < 0 || gridPoint.getX() > gridSize.getY() || gridPoint.getY() > gridSize.getY())
			{
				return (gridSize.getY()*2 + 1) - (gridPoint.getX() + gridPoint.getY() + 1);
			}
		else 
			{
				return this._zIndexArray[gridPoint.getX()][gridPoint.getY()];
			}
	
 	},
    
    //added by Raza
 getTimeInProperFormat:function (timeSent)
{
	
	var ageString="",time = 0, hours=0, min=0, days=0, minutes=0, sec = 0;
	
	if(timeSent < 60)
	{
		time = Math.floor(timeSent);
	}
	else
	{
		//time = (long)timeSent/60;
		//time =parseLong(timeSent)/60;
		time =Math.floor(timeSent/60);
		
	}
	
	if(time <= 0) {
		ageString=Core.Localization.getString("ready");
        return ageString;
	}
	if(time)//check any thing
	{
		if(timeSent < 60)
		{
			//ageString=(" %i sec left",time); TCUtil.getRelativeString(Core.Localization.getString("MM_EARNS_COINS_EVERY_MINUTES"),['50','25'])
			ageString=TCUtil.getRelativeString(Core.Localization.getString("secleft"),[time]);
			return ageString;
		}
		
		//if(time<2)
//		{			
//			//(" %i m left",time);
//			ageString=TCUtil.getRelativeString(Core.Localization.getString("mleft"),[time]);
//			return ageString;
//		}
		
		if(time<60)
		{	
			sec = Math.floor((+timeSent-time*60));
			if(sec > 0)
			{					 
				ageString=TCUtil.getRelativeString(Core.Localization.getString("msleft"),[time,sec]);
			}
			else
			{
				ageString=TCUtil.getRelativeString(Core.Localization.getString("mleft"),[time]);
			}
			return ageString;
		}
		
		// && ([fishObj getAdultAge]-[fishObj getCurrentAge])/60>=2)
		if(time/60 < 24)
		{
			//NgLogE('problem here');
			hours=Math.floor(time/60);
			min=Math.floor(time-hours*60);
			//NgLogE('hours here are'+hours);
			//NgLogE('minutes here are'+min);
			if(min > 0)
			{
				return TCUtil.getRelativeString(Core.Localization.getString("hmleft"),[hours,min]); 
			}
			return TCUtil.getRelativeString(Core.Localization.getString("hleft"),[hours]);
			
			//if(hours>1 && min>1)
//				return TCUtil.getRelativeString(Core.Localization.getString("hmleft"),[hours,min]); //(" %i hr, %i m left",hours,min);
//			if(hours>1 && min<2)
//				return TCUtil.getRelativeString(Core.Localization.getString("hmleft"),[hours,min]); //(" %i hr, %i m left",hours,min);
//			if(hours<2 && min>1)
//				return TCUtil.getRelativeString(Core.Localization.getString("hmleft"),[hours,min]); //[[[NSString alloc]  initWithFormat:@" %i hr, %i m left",hours,min] autorelease];
//			if(hours<2 && min<2)
//				return TCUtil.getRelativeString(Core.Localization.getString("hmleft"),[hours,min]);//[[[NSString alloc]  initWithFormat:@" %i hr, %i m left",hours,min] autorelease];
			
		}
		
		else
		{	
			//NgLogE('problem here in else condition');
			days=Math.floor(time/1440);
			hours=Math.floor((time-(days*1440))/60);
			minutes=Math.floor(time-(days*1440)-(hours*60));
			if(hours > 0)
			{
				if(minutes > 0)
				{
					return TCUtil.getRelativeString(Core.Localization.getString("dhmleft"),[days,hours,minutes]);
				}
				else
				{
					return TCUtil.getRelativeString(Core.Localization.getString("dhleft"),[days,hours]);
					
				}
			}
			if(minutes > 0)
			{
				return TCUtil.getRelativeString(Core.Localization.getString("dmleft"),[days,minutes]);
			}
			return TCUtil.getRelativeString(Core.Localization.getString("dleft"),[days]);
			
			//if(days==1 && hours<2)
//			{
//				return TCUtil.getRelativeString(Core.Localization.getString("dhmleft"),[days,hours,minutes]); //[[[NSString alloc]  initWithFormat:@"%i d, %i hr, %i m left",days,  hours,minutes] autorelease];
//			}
//			if(days==1 && hours>1)
//			{
//				return TCUtil.getRelativeString(Core.Localization.getString("dhmleft"),[days,hours,minutes]); //[[[NSString alloc]  initWithFormat:@"%i d, %i hr, %i m left",days,  hours,minutes] autorelease];
//			}
//			if(days>1 && hours<2)
//			{
//				return TCUtil.getRelativeString(Core.Localization.getString("dhmleft"),[days,hours,minutes]); //[[[NSString alloc]  initWithFormat:@"%i d, %i hr, %i m left",days,  hours,minutes] autorelease];
//			}
//			if(days>1 && hours>1)
//			{
//				return TCUtil.getRelativeString(Core.Localization.getString("dhmleft"),[days,hours,minutes]); //[[[NSString alloc]  initWithFormat:@"%i d, %i hr, %i m left",days,  hours,minutes] autorelease];
//			}
		}
	}
	return ageString;
},
	getTimeInProperFormatNew:function(timeSent)
	{	
		var ageString="";
		var time = 0;
		if(+timeSent <= 60)
		{
			time = +timeSent;
		}
		else
		{
			time = +timeSent/60;
		}
		
		if(time <= 0) {
			ageString="Ready";
			return ageString;
		}
		if(time)//check any thing
		{
			if(+timeSent <= 60)
			{
				//ageString=[[NSString alloc]  initWithFormat:@" %i sec left",time];
				ageString = this.getRelativeString(Core.Localization.getString("secleft"),[time]);
				return ageString;
			}
			
			if(time<2)
			{			
				//ageString=[[NSString alloc]  initWithFormat:@"%i min",time];
				ageString = this.getRelativeString(Core.Localization.getString("MIN"),[time]);

				return ageString;
			}
			
			if(time<60)
			{			
				//ageString=[[NSString alloc]  initWithFormat:@"%i mins",time];
				ageString = this.getRelativeString(Core.Localization.getString("MINS"),[time]);
				return ageString;
			}
			
			
			if(time/60 < 24)// && ([fishObj getAdultAge]-[fishObj getCurrentAge])/60>=2)
			{
				var hours = time/60.0;
				var newHour = ""+hours;
				var hr = newHour.split(".");
				if(+hr[1] > 0)
				{
					hr[1] = "."+hr[1].substring(0,1);
				}
				else
				{
					hr[1] = "";
				}
				//int min=time-hours*60;
				
				if(time%60 == 0)
				{
					if(hours < 2)
					{
						//ageString=[[NSString alloc]  initWithFormat:@"%.0f hr",hours];
						ageString = this.getRelativeString(Core.Localization.getString("HR"),[hr[0]+hr[1]]);

						//	return [ageString autorelease];
					}
					else
					{
						//ageString=[[NSString alloc]  initWithFormat:@"%.0f hrs",hours];
						ageString = this.getRelativeString(Core.Localization.getString("HRS"),[hr[0]+hr[1]]);

						//	return [ageString autorelease];
					}
				}
				else 
				{
					if(hours < 2)
					{
						///ageString=[[NSString alloc]  initWithFormat:@"%.1f hr",hours];
						ageString = this.getRelativeString(Core.Localization.getString("HR"),[hr[0]+hr[1]]);
						//	return [ageString autorelease];
					}
					else
					{
						///ageString=[[NSString alloc]  initWithFormat:@"%.1f hrs",hours];
						ageString = this.getRelativeString(Core.Localization.getString("HRS"),[hr[0]+hr[1]]);
						//	return [ageString autorelease];
					}
				}
				
				return ageString;
			}
			
			else
			{	
				var days= time/1440.0;
				var newDays= ""+days;
				var dy= newDays.split(".");	
				if(+dy[1] > 0)
				{
					dy[1] = "."+dy[1].substring(0,1);
				}
				else
				{
					dy[1] = "";
				}
				if(time%1440 == 0)
				{
					if(days < 2)
					{
						//ageString=[[NSString alloc]  initWithFormat:@"%.0f day",days];
									  
						ageString = this.getRelativeString(Core.Localization.getString("day"),[dy[0]+dy[1]]);
					}
					else
					{
						//ageString=[[NSString alloc]  initWithFormat:@"%.0f days",days];
						ageString = this.getRelativeString(Core.Localization.getString("DAYS"),[dy[0]+dy[1]]);

					}
				}
				else 
				{
					//ageString=[[NSString alloc]  initWithFormat:@"%.1f days",days];
					ageString = this.getRelativeString(Core.Localization.getString("DAYS"),[dy[0]+dy[1]]);

				}
				
				return ageString;
			}
		}
		return ageString;	
	},
	/////////////////////////////
	

	randomFromTo: function(from, to){
		return Math.floor(Math.random() * (to - from + 1) + from);
	},

									 
///////Sunilla temporary function to determine currency ////

	getPrice: function(itemArray)
	{
		if(itemArray && typeof itemArray != 'undefined')	
		{
			if(itemArray.nuggets == null || typeof itemArray.nuggets == 'undefined')
			{
				if(itemArray.coins != null )
				{
					return itemArray.coins;
				}
			}
			else
			{
				return itemArray.nuggets;
			}
		}
		return 0;//Will never return as atleast one price point will be there
	},
    
    getCurrency: function(itemArray)
    {
		if(itemArray && typeof itemArray != 'undefined')							 
	    {
	    	if(itemArray.nuggets == null || typeof itemArray.nuggets == 'undefined')
			{
				if(itemArray.coins != null )
				{
					return  kCurrencyType.kCurrencyTypeCoins;
		
				}
			}
			else
			{
				return kCurrencyType.kCurrencyTypeNuggets;
			}
		}
		return kCurrencyType.kCurrencyTypeCoins; //Will never return as atleast one price point will be there
    },
    
    getCurrencyValueForKey: function(model,key)
    {
		if(model)
		{
			var currencies = model.getCurrencyModel() , i = 0 , l = currencies.length , currencyVal;
			for(; i < l ; i++ )
			{
				if(currencies[i].getCurrency() == key)
				{
					currencyVal = currencies[i];
				
				}
			}
			if(!currencyVal)
			{
				return -1;
			}
			return currencyVal.getValue();
		}
		else
		{
			return -1;
		}
    },
									 
	getStoreObjectType: function(storeObject)
    {
    	if(storeObject) {
			if(!storeObject.parent || !storeObject.parent.parent)
			{
				return;
			}
			var storeVisibleId = storeObject.parent.parent.visible_id;
			if(storeVisibleId) {
				if(storeVisibleId == '1' || storeVisibleId == '7') {
					return kObjectType.kObjectAnimal;
				} else if(storeVisibleId == '2') {
					return kObjectType.kObjectHabitat;
				} else if(storeVisibleId == '5'){
					return kObjectType.kObjectConcession;
				}
				else if(storeVisibleId == '3'){
					return kObjectType.kObjectDecoration;
				}
			}
		}

    },			
    					 
	getBasePathForResourceType:function(storeObj,resourceType) 
	{
		var resource = GAResourceUtils.getResourceOfType(storeObj, resourceType);
		var basePath = GAResourceUtils.getResourceSavePath(storeObj, resource);
		return basePath;
	},  

	getEntryPointsArray: function() 
	{ 
		var gridSize = MMGameState.getCurrentUser().getSelectedZoo().getGridCols();
		var entryPoints = new Array();
		var p = this.convertGridPointToLayerPoint(new Core.Vector(gridSize/2,2));
	
		var point1 = new Core.Vector(0,0);
		point1.setX( p.getX() );
		point1.setY( p.getY() );
		entryPoints[entryPoints.length] = point1;

		var point2 = new Core.Vector(0,0);

		point2.setX(point1.getX() + 300);
		point2.setY(point1.getY() + 175);
		entryPoints[entryPoints.length] = point2;
		var temp = this.convertLayerPointToGridPoint(new Core.Vector(point2.getX(),point2.getY()));
		
		return entryPoints;
	},
	getBredGroupName:function(bredGroup)
	{
		var connectModel = GAGameLoader.getResponseObject().getCustomAttributes();
		var groupName = connectModel[bredGroup];
		//console.log("bred group name " + groupName);							  
		if(groupName)
		{
			return groupName;
			
		}
		return Core.Localization.getString("UNKNOWN");							  
		//var jsonStr = JSON.stringify(connectModel);
		//console.log("JSON string: " + jsonStr);
	},

	getConstructionDimensions: function(x,y)
	{
		if( x == 2 && y == 2 )
		{
			return new Core.Vector(208,110);
		}
		else if( x == 3 && y ==3 )
		{
			return new Core.Vector(384,222);
		}
		else if( (x == 4 && y == 4) || (x == 5 && y == 5))
		{
			return new Core.Vector(611,372);
		}
	},
	
	validateString:function(str)
	{
		if ( str == null )
			return null;
		//var newStr = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
		var newStr = str.replace(/\s/g, "");
		newStr = newStr.replace(/\n/g,'');
		if ( newStr.length == 0 )
			return null;
		return newStr;
	},
	
	trimWhiteSpace: function(str)
	{
		return str.replace(/\s/g, "");
		//return str.replace(/^\s+|\s+$/g, '');
	},
	
	
	getModelType: function(storeId)
	{
		var validStoreId = true;
		var array = storeId.split("_");
		var i = 0 , l = array.length;
		for( ; i < l ; i++)
		{
			if(!isNaN(parseInt(array[i])) && isFinite(array[i]))
			{	
				validStoreId = true;
			}
			else
			{
				validStoreId=false;
			}
		}
		
		if(validStoreId==true && array.length==1 )
		{
			return kModelType.kStoreModel;
		}
		else if (validStoreId==true && array.length==2)
		{
			return kModelType.kCategoryModel;
		}
		
		else if (validStoreId==true && array.length==3 )
		{
			return kModelType.kItemModel;
		}
		else
		{
		}
				
		return null;
				
	},
	
	startsWith : function(str,prefix) {
	    return str.indexOf(prefix) === 0;
	},
	
	endsWith: function(str,suffix) {
	    return str.match(suffix+"$") == suffix;
	},
    
    getGrandOpeningDimensions: function(x,y)
	{
		if( x == 2 && y == 2 )
		{
			return new Core.Vector(237,198);
		}
		else if( x == 3 && y ==3 )
		{
			return new Core.Vector(384,305);
		}
		else if( (x == 4 && y == 4) || (x == 5 && y == 5))
		{
			return new Core.Vector(611,501);
		}
	},
	
	isRequiredInVersion: function(reqVersion)
	{
		if(+reqVersion > +MM_VERSION_NUMBER)
		{
			return false;
		}
		return true;
	},
	
	getPrice: function(itemArray)
	{
		if(!itemArray || itemArray.nuggets == null || typeof itemArray.nuggets == 'undefined')
		{
			
			if(itemArray && itemArray.coins != null )
			{
				
				return itemArray.coins;
			}
		}
		else
		{
			
			return itemArray.nuggets;
		}

		return 0;//Will never return as atleast one price point will be there
		 
	},
	
	getDummyFriendObject: function()
	{
		var object = new Object();
		object.displayName = "Cobalt Play";
		object.id = "999";
		return object;
	},
	
	getCurrency: function(itemArray)
    {
    	if(!itemArray || itemArray.nuggets == null || typeof itemArray.nuggets == 'undefined')
		{

			if(itemArray && itemArray.coins != null )
			{
		
				return  kCurrencyType.kCurrencyTypeCoins;
			}
		}

        return kCurrencyType.kCurrencyTypeNuggets;
    },
	
	destroy: function()
	{
		if(this._zIndexArray)
		{
			var count = this._zIndexArray.length, i=0;
			for(; i < count ; i++)
			{
				
				delete this._zIndexArray[i];
				
			}
			delete this._zIndexArray;
		}
	},
	


});